package com.itheima.web;

import com.baomidou.mybatisplus.extension.api.R;
import com.itheima.dto.CheckGroupDto;
import com.itheima.dto.SetmealDto;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealGroupService;
import com.itheima.service.SetmealService;
import com.itheima.utils.FileUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * company: www.abc.com
 * Author: 29746
 * Create Data: 2020/11/13
 */
@RestController
@RequestMapping("/setmeal")
@Api("套餐管理")
public class SetmealController {

    @Reference
    private SetmealService setmealService;

    @Reference
    private SetmealGroupService setmealGroupService;

    @GetMapping("/findAll")
    @ApiOperation("查询所有套餐") //逻辑删除后修改的查询方法
    public List<Setmeal> findAll(){
        return  setmealService.findAll();
    }


    @PostMapping("/save")
    @ApiOperation("新增和修改套餐")
    public void save(@RequestBody SetmealDto setmealDto){
        setmealService.saveSetmealAndGroup(setmealDto);
    }

    @GetMapping("/remove/{id}")
    @ApiOperation("删除套餐")
    public boolean deleteById(@PathVariable("id") Long id){
        boolean flag = setmealService.deleteById(id);
        return flag;
    }


    @PostMapping("/findByPage")
    @ApiOperation("分页查询套餐")
    public PageResult findByPage(@RequestBody QueryPageBean queryPageBean){
        return setmealService.findByPage(queryPageBean);
    }

    @GetMapping("/selectBySetmealId/{setmealId}")
    @ApiOperation("修改时回显检查组")
    public Long[] selectBySetmealId(@PathVariable("setmealId") Long setmealId){
        return setmealGroupService.selectBySetmealId(setmealId);
    }



    @GetMapping("/clearOssObject")
    @ApiOperation("删除垃圾图片") //删除垃圾图片
    public void clearOssObject(){
         setmealService.clearOssObject();
    }

}
